import { getUserData, getAttendanceData, getProjectData, getSalaryData, fileDownload} from '@/api'

const state = {
	// 部门信息，含id和名称
	departmentArr: []
}

const mutations = {
	getDepartment(state, departmentArr){
		state.departmentArr = departmentArr
	}
}

const actions = {
	// 文件下载
	fileDownload({commit}, url) {
		let res = fileDownload(url)
		return res
	},
	// 获取员工列表
	async UserData({ commit }, params) {
		let res = await getUserData(params)
		// 存储部门信息
		let departmentArr = []
		for(let i = 0 ; i < res.data[0].length ; i++){
			departmentArr[i] = {}
			departmentArr[i].department_id = res.data[0][i].department_id
			departmentArr[i].department_name = res.data[0][i].department_name
		} 
		commit('getDepartment', departmentArr)
		return res
	},
	// 获取考勤信息数据
	async getAttendanceData({ commit }, params) {
		let res = await getAttendanceData(params)
		return res
	},
	// 获取项目数据的接口
	async getProjectData({ commit }) {
		let res = await getProjectData()
		return res
	},
	// 获取工资数据的接口
	async getSalaryData({ commit }, params) {
		let res = await getSalaryData(params)
		return res
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}